package belf.migrate.engine.job.verify.utils;

import belf.migrate.api.common.DatabaseIdentifier;
import belf.migrate.core.jdbc.TypeModel;

import java.util.Locale;
import java.util.Map;

public class ColumnTypeUtil {

    public static boolean columnTypeEqual(String sourceType,
                                          String sinkType,
                                          String sourceCatalog,
                                          String sinkCatalog,
                                          Map<String, TypeModel> mapping) {
        TypeModel typeModel = mapping.get(sourceType.toUpperCase(Locale.ROOT));
        if (sinkType.equalsIgnoreCase(typeModel.getTo())) {
            return true;
        }

        switch (sinkCatalog) {
            case DatabaseIdentifier.DAMENG:
                if (DMConventType.contains(typeModel.getTo())) {
                    return DMConventType.equals(sinkType, typeModel.getTo());
                }
            case DatabaseIdentifier.KINGBASE:
                if (KingbaseConventType.contains(typeModel.getTo())) {
                    return KingbaseConventType.equals(sinkType, typeModel.getTo());
                }
            case DatabaseIdentifier.GBASE_8S:
                if (GBase8sConventType.contains(typeModel.getTo())) {
                    return GBase8sConventType.equals(sinkType, typeModel.getTo());
                }

        }
        return false;

    }

}
